package com.niuniu.rushdorm.pojo.vo;

import com.niuniu.rushdorm.exception.ReportedException;
import com.niuniu.rushdorm.util.StatusEnum;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @author Meng
 * 2022/11/9
 */
@Getter
@Setter
@NoArgsConstructor
public class ResultVO {
    private Integer code;
    private String message;
    private Object data;

    public static ResultVO success(Object data){
        ResultVO resultVO = new ResultVO();
        resultVO.setData(data);
        resultVO.setCode(StatusEnum.SUCCESS.getCode());
        resultVO.setMessage(StatusEnum.SUCCESS.getMsg());
        return resultVO;
    }

    public static ResultVO fail(ReportedException e){
        StatusEnum statusEnum = e.getStatus();
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(statusEnum.getCode());
        resultVO.setMessage(statusEnum.getMsg());
        return resultVO;
    }
}
